home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 22
/
Commodore_Free_Issue_22_2008_Commodore_Computer_Club.d64
/
t.b guide 7.2
< prev
next >
Wrap
Text File
|
2023-02-26
|
12KB
|
396 lines
u
In the Beginning CHAPTER 7 SECTION 2
\Lord Ronin from Q-Link\
Continued from Section 1
Line 90 is another one that may have
given you trouble in the way I wrote
it. Got the print command and the
quote, there really is a space before
the first left cursor movement,
followed by the second left cursor
then the symbol and then another left
cursor.
100 sets the time delay to be the same
as line 50. 110 is the same as line
60. Line 120 is the same as 70. Line
130 simple tells the entire programme
to start over again. The way the
programme is laid out, the variable
labels of TM and BL can be reused.
Line 40 is the left to right work
horse of the programme, they Prints a
space that will erase the previous
symbol on the line, then print the
symbol, and then does a left cursor
over the symbol, getting ready to do
the erase and print all over again.
Line 90 is the same except it is doing
everything in the opposite direction.
See how it is moved with the need of
the extra erasures of the symbol to
move delete and print.
OK when you have this working, feel
free to save it. Feeling a bit
experimental? Well then change the
symbol, do this all in upper case for
now. Tired of the speed that it moves,
try altering the TM variable. One
thing that I have the local group
members do is to make a black spade go
from left to right. But how about a
red diamond going from right to left.
No problem in changing the symbol, How
to do the colour?
Well that takes retyping out the line,
just need one more thing in the line.
Need to press the control and 1 key
for black. You will see a different
graphic symbol show up. If not and you
see the cursor turn black, you forgot
to open the print statement by
retyping the " symbol. Same for the
diamond or heart, retype the line and
add the control 3 and a symbol will
appear, run the programme. Did you put
them in the right place? If not play
with it a while. Maybe you want to
change the screen and border colour,
make a line 22 that says ?"my
animation" or something like that. We
have covered the basics on how to do
that. Save it if you wish, the thing
is, that you have made it on your own.
There is that thing moving back and
forth on the screen, You did it! You
have just programmed a visual thing.
Now we come to the INPUT command. A
way to have the user interact with
what you have written. If you went
through my thing on programmes for the
C=. You may have not fallen asleep on
the Text Adventures part. Simple and
easy early to learn Text Adventures,
use INPUT as the way to have the
player enter information for the game.
Lets new the computer and do the
following from the book.
10 INPUT A$
20 ?"you typed: ";A$
30 ?
40 GOTO10
That is simple and there are two
things here that are new, Ill get to
the input in a moment. That print
command on line 30, what is it going
to print? The answer is Nothing! As
you see on the line there is nothing
to print, so all it is going to do is
drop one line down. Since this
programme can be run over and over
again, that space just separates what
you have done from the next part. No
matter what you type a word, a number,
a gfx, a letter, as soon as you hit
the return key what every you input,
is output to the screen. Can you see
at this time the use of the IF THEN
with INPUT? I mean you write a
question and IF the answer is wrong
THEN the programme prints a nasty
response? <VBESG>
Well the secret isn't a big one, you
can see on the first line that there
is a variable, this will be for the
input. Line 20 prints out both the
message and what you printed, just
that simple. Putting it together with
other things is where the "fun" enters
the game. I'll add here that there are
some people who dislike the input
command. Also there is available some
code to remove that question mark at
the end of the input line when you run
the programme. Seen it in action,
never found my copy of that command
after a move.
OK here is a more understandable use
of the INPUT command, the following
will convert standard Fahrenheit to
Centigrade and the reverse. New the
machine and lets start.
1 REM TEMPERATURE CONVERSION PROGRAMME
5 ?"<clear/home>"
10 ?"convert from farhenheit or
celsius (f/c)":INPUT a$
20 IFA$=""THEN 20
30 IFA$="F"THEN100
40 IFA$<>"C"THEN10
50 INPUT"ENTER DEGREES CELSIUS: ";C
60 F=(C*9)/5+32
70 ?C;" DEG. CELSIUS = "; F;" DEG.
FAHRENHEIT"
80 ?
90 GOTO10
100 INPUT"ENTER DEGREES FAHRENHEIT:
";F
110 C=(F-32)*5/9
120 ? F;" DEG. FAHRENHEIT = ";C;" DEG.
CELSIUS"
130 ?
140 GOTO10
A lot of work to do something an old
calculator I had would do with a few
pushes of the keys, but there is a lot
to see here. I mean we are familiar to
some degree with many of the
components of presented commands, See
variables, math work, print
statements. Now lets hope that I wrote
it down right from the book, as we are
going into this one.
REM part we covered, doing that
shifted/clear home as well, Line 10 is
a little different, We have the
familiar print statement The : to
separate commands on a line, But now
we have an INPUT statement, Creating
the variable a$ which should be either
a f or a c.
Lines 20-40 are a new thing, sure they
are the IF THEN statements, but on
line 20 there is something new those
"", and no space between them. The
line is saying that if a$ is nothing,
(no key press), then go to line 20.
Note here that I wrote it as go to
line 20, in programming you do not
have to write that go to part, just
the line number. OK what is happening
is that the programme is going to sit
there and wait for you do type in the
right thing, before it goes anywhere
else.
Line 30 works if a$ is the f, inputted
from the keyboard, ff so then the
programme will jump to line 100. Ah
here is a new one, Line 40 has the
does not equal c part, reading the
line says that if the input that the
user does from the keyboard doesn't
equal c, the programme goes back to
line 10 saying printing for the (f/c),
and maybe the user will understand
what he is to type in for the input.
Covers here the input of the variable
c as well as rejecting all other non
recognised inputs, done in just one
line.
Line 50 is an input and takes the
centigrade degrees making them into
the variable c. Line 60 does the math
for us, Line 70 prints out what the
centigrade is in standard. Here you
may need to alter this for spaces to
have things line up correctly. Line 80
is a print statement to move down one
line. Line 90 takes it back to line 10
to start over again. Line 100 is the
same with the input for Fahrenheit,
giving f as the variable. Line 110
does the math, Line 120 prints out the
variable as a number and the text,
again here you may need to adjust for
spacing. Line 130 does that drop down
again and Line 140 sends the programme
back to line 10 to start over again.
A few things need to be added at this
point, you can change the words in the
statements. As I am obviously not a
fan of metric, I wrote mine as
standard for Fahrenheit, and
centigrade for Celsius, as that was
the term I was taught for the metric
measurement. Doesn't hurt a thing if
it makes you more comfortable, if you
feel like experimenting, try changing
the colours of the text, the border
and the screen. Be surprised at how
that will change the look and feel of
the programme. Now that go to Line 10
on lines 90 and 140. Takes you back to
the start of the input for the
programme. What it will also do is
keep making a space from the print
line, and then print the first line
over again on your screen. If you
don't want a long list of that and the
answers on your screen, change that
goto 10 to goto 5. That line clears
the screen and puts the cursor at row
0 column 0.
Sort of like input, we have GET. This
one works with each key press. New the
PC and type in.
1 ?"<CLEAR/HOME>"
10 GETA$:IFA$=""THEN10
20 ?A$;
30 GOTO10
Run it and see what happens, ok I'll
let you know now, but it is more fun
to run it. <G> Each character from the
keyboard you type shows up one by one
on a single line. WHY? OK lets tear it
apart. Got what happens in line 1 as
the clear screen and start at the top
left, Line 10 has a variable called a$
and the if then statement. Also in
that if then statement the "" placed
together, A point to bring up for
those that intend to use type in
books, Font changes in the different
books may confuse you to if there is
or isn't a space between the quotes.
Most of the time there isn't, but it
can look like it on the book page. We
have a new command called GET, What
does it do? Pretty much as it says, it
is going to GET something. In this
example, It wants to GET the keyboard
input, and won't move along, hmm as
stubborn as me, till it GETs what it
is looking for. That is why nothing
happens till you press a key. Works
that way for every time you press a
key, patiently waiting for you to
enter a something, but takes it only
one character at a time. Once you
press a key, the programme goes right
to line 20, where it prints that
character where it is the variable a$.
Next is line 30 that loops it back to
the start.
The reason that it prints the
characters all in a line is the use of
that ; symbol. Change that to , and
you will have the characters in neat
rows at the 4 tab points on the
screen. Drop the , and or the ; and it
just goes along the left edge of the
screen. A simple programme that with a
slight addition is how I have people
type in their name or other
information on the little intro
screens I make from time to time for
the club. Also basically the same way
that callers do when they log into the
BBS and type anything in the message
bases.
The Commodore book thinks that you
saved that previous temperature
convention thing. They want to show
you how to shorten the programme down
a bit, so they show in the book that
you can alter lines 10-40 from all
those IF THEN statements to
10 ? "Convert from Fahrenheit or
Celsius (F/C)"
20 GET A$: IF A$ = "" THEN 20
40 IF A$ <> "C" THEN 20
I dig RPGames. Have done since 1978ce
when I was in my late 20s, no idea how
many dice I have rolled or how many
times I have rolled them. Nice to know
that the C= can do dice rolling, but
how to do that? Step by step me
laddieo. <G> New the system and lets
do the following.
10 FOR X=1TO10
20 ?RND(1),
30 NEXT
Well run that and you see a pair of
columns of numbers less than 1. OK
that RND thing is pretty much a random
number generator, but there is more to
it than that, if you saw the same
information on your screen as mine,
then it wouldn't be random would it?
But that is rather useless for dice
rolling. The book now wants you to
change line 20 to read.
20 ? 6*RND(1),
Well running that and you still have
some weird numbers, but you do have
something to the left of the decimal
point. OK lets change line 20 again to
read...
20 ? INT(6*RND(1)),
Ah now we have solid numbers, But wait
a moment 0-5 is not what we want for a
D6. So change the line again to
read...
20 ? INT(6*RND(1))+1,
Yeah here we go, from 1-6 gamers you
can change the 6 to be a 4, 8, 10, 12,
20, 30 and 100, Reflecting the
different game dice. Really advanced
stuff is using the KB GFX to show the
numbers. I've seen animated bits of
dice rolling, along loads of other
pretty pretties on the screen. All
comes from this little part.
INT(LOWER LIMIT+(UPPER-LOWER+1)
*RND(1))
Ah that is supposed to be on one line,
i know that it doesn't make any sense
looking like that and there is a thing
that will be in the next section that
will require you to use this part. So
I'll put it out in that area.
You see the next area is where we make
a guessing game. Simple but remember
you are the one creating it, I'll go
over the parts for us, and then we
will do that weird line.
Continued next month.